﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.WebNemo.Business.Groups;

namespace blackhouse.NemoBlog.Business {
    public class NemoBlogPost : GroupRecord {

        #region Properties

        public string Title {
            get { return this.GetString("title"); }
            set { this.SetValue("title", value); }
        }

        public string ShortTitle {
            get { return this.GetString("shortTitle"); }
            set { this.SetValue("shortTitle", value); }
        }

        public string ShortDescription {
            get { return this.GetString("shortDescription"); }
            set { this.SetValue("shortDescription", value); }
        }

        public string Lid {
            get { return this.GetString("lid"); }
            set { this.SetValue("lid", value); }
        }

        public string Content {
            get { return this.GetString("content"); }
            set { this.SetValue("content", value); }
        }

        public bool IsPublished {
            get {
                if (this.IsNotNull("published"))
                    return this.GetBoolean("published");
                else
                    return false;
            }
            set { this.SetValue("published", value); }
        }

        public DateTime PublishDate {
            get {
                if (this.IsNotNull("publishDate"))
                    return this.GetDateTime("publishDate");
                else
                    return DateTime.MinValue;
            }
            set { this.SetValue("publishDate", value); }
        }

        public string PostUrl {
            get { return this.GetString("url"); }
            set { this.SetValue("url", value); }
        }
        public int ModuleId {
            get { return this.GetInt32("moduleId"); }
            set { this.SetValue("moduleId", value); }
        }

        private Guid postGuid = Guid.Empty;
        private bool postGuidParsed = false;

        public Guid PostGuid {
            get {
                if (!postGuidParsed) {
                    postGuidParsed = true;
                    Guid.TryParse(this.GetString("guid"), out this.postGuid);
                }
                return this.postGuid;
            }
            set {
                this.postGuid = value;
                this.postGuidParsed = true;
                this.SetValue("guid", this.postGuid.ToString());
            }
        }

        public int PostId {
            get { return this.RecordId; }
        }

        private NemoBlogTag[] tags;
        public NemoBlogTag[] Tags {
            get {
                if (this.tags == null)
                    this.tags = this.GetRecords<NemoBlogTag>("tags");
                return this.tags;
            }
        }

        #endregion

        #region Constructors

        public NemoBlogPost(int postId)
            : base(NemoBlogPosts.GROUP_POSTS, postId) { }

        public NemoBlogPost() : base() { }

        #endregion

    }
}
